package com.housekeeping.housekeeping.administrator.adminsinformation.controller;

import com.alibaba.fastjson.JSONObject;
import com.housekeeping.housekeeping.administrator.adminsinformation.service.insert.InsertService;
import com.housekeeping.housekeeping.administrator.adminsinformation.service.insert.InsertServiceImpl;
import com.housekeeping.housekeeping.administrator.entity.AdminsInformation;
import com.housekeeping.housekeeping.administrator.utils.ResponseEntity;
import com.housekeeping.housekeeping.administrator.utils.ResponseUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/information/insert")
public class InsertController extends HttpServlet {
    private InsertService service=new InsertServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html:charset=utf-8");
        String admins = req.getParameter("data");
        AdminsInformation adminsInformation = JSONObject.parseObject(admins, AdminsInformation.class);
        int count = service.insertion(adminsInformation);
        ResponseEntity<Integer> entity=null;
            if (count>0){
                entity = ResponseEntity.success(count);
            }else {
                entity=ResponseEntity.error(400,"账号已存在");
            }
        ResponseUtils.responseJson(resp,entity);
    }
}
//{"name":"李四":"account":"asdfgh","password":123456,"phoneNumber":123456789,"jurisdiction":"设计":"remark":"哈哈哈"}
